#include "seat.h"
#include "ui_seat.h"

Seat::Seat(datebase *db,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Seat)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
    seat_mydb=db;
}

Seat::~Seat()
{
    delete ui;
}

void Seat::on_pushButton_NewSeatQuit_clicked()
{
    this->close();
}

void Seat::on_pushButton_NewSeatAdd_clicked()
{
    int count=ui->lineEdit_NewSeatNum->text().toInt();
    int seat_no=ui->lineEdi_NewSeatBegin->text().toInt();
    QString str,name;
    name=ui->lineEdit_NewSeatName->text();
    for(int i=0;i<count;i++)
    {
      str=QString("%1%2").arg(name).arg(seat_no+i);
      seat_insert(str);
    }
    QMessageBox::information(NULL, QString("提示"), QString("车位添加完成"));
    this->close();
}

void Seat::seat_insert(QString name)
{
    QSqlQuery query(seat_mydb->sqlite_db);
    query.clear();
    query.prepare("insert into vehicle_seat(print_code,created_at) values(?,?)");
    query.bindValue(0,name);
    query.bindValue(1,QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
    query.exec();
    query.next();
}

